<?php


/**
 * Base class that represents a row from the 'users' table.
 *
 *
 *
 * @package    propel.generator.damages.om
 */
abstract class DamagesBaseUsers extends BaseObject implements Persistent
{
    /**
     * Peer class name
     */
    const PEER = 'DamagesUsersPeer';

    /**
     * The Peer class.
     * Instance provides a convenient way of calling static methods on a class
     * that calling code may not be able to identify.
     * @var        DamagesUsersPeer
     */
    protected static $peer;

    /**
     * The flag var to prevent infinit loop in deep copy
     * @var       boolean
     */
    protected $startCopy = false;

    /**
     * The value for the id field.
     * @var        int
     */
    protected $id;

    /**
     * The value for the permission_id field.
     * @var        int
     */
    protected $permission_id;

    /**
     * The value for the email field.
     * @var        string
     */
    protected $email;

    /**
     * The value for the first_name field.
     * @var        string
     */
    protected $first_name;

    /**
     * The value for the last_name field.
     * @var        string
     */
    protected $last_name;

    /**
     * The value for the position field.
     * @var        string
     */
    protected $position;

    /**
     * The value for the phone field.
     * @var        string
     */
    protected $phone;

    /**
     * The value for the phone_mobile field.
     * @var        string
     */
    protected $phone_mobile;

    /**
     * The value for the phone_fax field.
     * @var        string
     */
    protected $phone_fax;

    /**
     * The value for the password field.
     * @var        string
     */
    protected $password;

    /**
     * The value for the force_password_change field.
     * Note: this column has a database default value of: 1
     * @var        int
     */
    protected $force_password_change;

    /**
     * The value for the created field.
     * @var        string
     */
    protected $created;

    /**
     * The value for the modified field.
     * @var        string
     */
    protected $modified;

    /**
     * @var        Permissions
     */
    protected $aPermissions;

    /**
     * @var        PropelObjectCollection|DamagesSessions[] Collection to store aggregation of DamagesSessions objects.
     */
    protected $collSessionss;
    protected $collSessionssPartial;

    /**
     * @var        PropelObjectCollection|DamagesCarDamages[] Collection to store aggregation of DamagesCarDamages objects.
     */
    protected $collCarDamagessRelatedByLsId;
    protected $collCarDamagessRelatedByLsIdPartial;

    /**
     * @var        PropelObjectCollection|DamagesCarDamages[] Collection to store aggregation of DamagesCarDamages objects.
     */
    protected $collCarDamagessRelatedByOlId;
    protected $collCarDamagessRelatedByOlIdPartial;

    /**
     * @var        PropelObjectCollection|DamagesUserDealers[] Collection to store aggregation of DamagesUserDealers objects.
     */
    protected $collUserDealerss;
    protected $collUserDealerssPartial;

    /**
     * Flag to prevent endless save loop, if this object is referenced
     * by another object which falls in this transaction.
     * @var        boolean
     */
    protected $alreadyInSave = false;

    /**
     * Flag to prevent endless validation loop, if this object is referenced
     * by another object which falls in this transaction.
     * @var        boolean
     */
    protected $alreadyInValidation = false;

    /**
     * An array of objects scheduled for deletion.
     * @var		PropelObjectCollection
     */
    protected $sessionssScheduledForDeletion = null;

    /**
     * An array of objects scheduled for deletion.
     * @var		PropelObjectCollection
     */
    protected $carDamagessRelatedByLsIdScheduledForDeletion = null;

    /**
     * An array of objects scheduled for deletion.
     * @var		PropelObjectCollection
     */
    protected $carDamagessRelatedByOlIdScheduledForDeletion = null;

    /**
     * An array of objects scheduled for deletion.
     * @var		PropelObjectCollection
     */
    protected $userDealerssScheduledForDeletion = null;

    /**
     * Applies default values to this object.
     * This method should be called from the object's constructor (or
     * equivalent initialization method).
     * @see        __construct()
     */
    public function applyDefaultValues()
    {
        $this->force_password_change = 1;
    }

    /**
     * Initializes internal state of DamagesBaseUsers object.
     * @see        applyDefaults()
     */
    public function __construct()
    {
        parent::__construct();
        $this->applyDefaultValues();
    }

    /**
     * Get the [id] column value.
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Get the [permission_id] column value.
     *
     * @return int
     */
    public function getPermissionId()
    {
        return $this->permission_id;
    }

    /**
     * Get the [email] column value.
     *
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Get the [first_name] column value.
     *
     * @return string
     */
    public function getFirstName()
    {
        return $this->first_name;
    }

    /**
     * Get the [last_name] column value.
     *
     * @return string
     */
    public function getLastName()
    {
        return $this->last_name;
    }

    /**
     * Get the [position] column value.
     *
     * @return string
     */
    public function getPosition()
    {
        return $this->position;
    }

    /**
     * Get the [phone] column value.
     *
     * @return string
     */
    public function getPhone()
    {
        return $this->phone;
    }

    /**
     * Get the [phone_mobile] column value.
     *
     * @return string
     */
    public function getPhoneMobile()
    {
        return $this->phone_mobile;
    }

    /**
     * Get the [phone_fax] column value.
     *
     * @return string
     */
    public function getPhoneFax()
    {
        return $this->phone_fax;
    }

    /**
     * Get the [password] column value.
     *
     * @return string
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Get the [force_password_change] column value.
     *
     * @return int
     */
    public function getForcePasswordChange()
    {
        return $this->force_password_change;
    }

    /**
     * Get the [optionally formatted] temporal [created] column value.
     *
     *
     * @param string $format The date/time format string (either date()-style or strftime()-style).
     *				 If format is null, then the raw DateTime object will be returned.
     * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null
     * @throws PropelException - if unable to parse/validate the date/time value.
     */
    public function getCreated($format = 'Y-m-d H:i:s')
    {
        if ($this->created === null) {
            return null;
        }


        try {
            $dt = new DateTime($this->created);
        } catch (Exception $x) {
            throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created, true), $x);
        }

        if ($format === null) {
            // Because propel.useDateTimeClass is true, we return a DateTime object.
            return $dt;
        } elseif (strpos($format, '%') !== false) {
            return strftime($format, $dt->format('U'));
        } else {
            return $dt->format($format);
        }
    }

    /**
     * Get the [optionally formatted] temporal [modified] column value.
     *
     *
     * @param string $format The date/time format string (either date()-style or strftime()-style).
     *				 If format is null, then the raw DateTime object will be returned.
     * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null
     * @throws PropelException - if unable to parse/validate the date/time value.
     */
    public function getModified($format = 'Y-m-d H:i:s')
    {
        if ($this->modified === null) {
            return null;
        }


        try {
            $dt = new DateTime($this->modified);
        } catch (Exception $x) {
            throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->modified, true), $x);
        }

        if ($format === null) {
            // Because propel.useDateTimeClass is true, we return a DateTime object.
            return $dt;
        } elseif (strpos($format, '%') !== false) {
            return strftime($format, $dt->format('U'));
        } else {
            return $dt->format($format);
        }
    }

    /**
     * Set the value of [id] column.
     *
     * @param int $v new value
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function setId($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->id !== $v) {
            $this->id = $v;
            $this->modifiedColumns[] = DamagesUsersPeer::ID;
        }


        return $this;
    } // setId()

    /**
     * Set the value of [permission_id] column.
     *
     * @param int $v new value
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function setPermissionId($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->permission_id !== $v) {
            $this->permission_id = $v;
            $this->modifiedColumns[] = DamagesUsersPeer::PERMISSION_ID;
        }

        if ($this->aPermissions !== null && $this->aPermissions->getId() !== $v) {
            $this->aPermissions = null;
        }


        return $this;
    } // setPermissionId()

    /**
     * Set the value of [email] column.
     *
     * @param string $v new value
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function setEmail($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->email !== $v) {
            $this->email = $v;
            $this->modifiedColumns[] = DamagesUsersPeer::EMAIL;
        }


        return $this;
    } // setEmail()

    /**
     * Set the value of [first_name] column.
     *
     * @param string $v new value
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function setFirstName($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->first_name !== $v) {
            $this->first_name = $v;
            $this->modifiedColumns[] = DamagesUsersPeer::FIRST_NAME;
        }


        return $this;
    } // setFirstName()

    /**
     * Set the value of [last_name] column.
     *
     * @param string $v new value
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function setLastName($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->last_name !== $v) {
            $this->last_name = $v;
            $this->modifiedColumns[] = DamagesUsersPeer::LAST_NAME;
        }


        return $this;
    } // setLastName()

    /**
     * Set the value of [position] column.
     *
     * @param string $v new value
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function setPosition($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->position !== $v) {
            $this->position = $v;
            $this->modifiedColumns[] = DamagesUsersPeer::POSITION;
        }


        return $this;
    } // setPosition()

    /**
     * Set the value of [phone] column.
     *
     * @param string $v new value
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function setPhone($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->phone !== $v) {
            $this->phone = $v;
            $this->modifiedColumns[] = DamagesUsersPeer::PHONE;
        }


        return $this;
    } // setPhone()

    /**
     * Set the value of [phone_mobile] column.
     *
     * @param string $v new value
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function setPhoneMobile($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->phone_mobile !== $v) {
            $this->phone_mobile = $v;
            $this->modifiedColumns[] = DamagesUsersPeer::PHONE_MOBILE;
        }


        return $this;
    } // setPhoneMobile()

    /**
     * Set the value of [phone_fax] column.
     *
     * @param string $v new value
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function setPhoneFax($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->phone_fax !== $v) {
            $this->phone_fax = $v;
            $this->modifiedColumns[] = DamagesUsersPeer::PHONE_FAX;
        }


        return $this;
    } // setPhoneFax()

    /**
     * Set the value of [password] column.
     *
     * @param string $v new value
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function setPassword($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->password !== $v) {
            $this->password = $v;
            $this->modifiedColumns[] = DamagesUsersPeer::PASSWORD;
        }


        return $this;
    } // setPassword()

    /**
     * Set the value of [force_password_change] column.
     *
     * @param int $v new value
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function setForcePasswordChange($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->force_password_change !== $v) {
            $this->force_password_change = $v;
            $this->modifiedColumns[] = DamagesUsersPeer::FORCE_PASSWORD_CHANGE;
        }


        return $this;
    } // setForcePasswordChange()

    /**
     * Sets the value of [created] column to a normalized version of the date/time value specified.
     *
     * @param mixed $v string, integer (timestamp), or DateTime value.
     *               Empty strings are treated as null.
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function setCreated($v)
    {
        $dt = PropelDateTime::newInstance($v, null, 'DateTime');
        if ($this->created !== null || $dt !== null) {
            $currentDateAsString = ($this->created !== null && $tmpDt = new DateTime($this->created)) ? $tmpDt->format('Y-m-d H:i:s') : null;
            $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
            if ($currentDateAsString !== $newDateAsString) {
                $this->created = $newDateAsString;
                $this->modifiedColumns[] = DamagesUsersPeer::CREATED;
            }
        } // if either are not null


        return $this;
    } // setCreated()

    /**
     * Sets the value of [modified] column to a normalized version of the date/time value specified.
     *
     * @param mixed $v string, integer (timestamp), or DateTime value.
     *               Empty strings are treated as null.
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function setModified($v)
    {
        $dt = PropelDateTime::newInstance($v, null, 'DateTime');
        if ($this->modified !== null || $dt !== null) {
            $currentDateAsString = ($this->modified !== null && $tmpDt = new DateTime($this->modified)) ? $tmpDt->format('Y-m-d H:i:s') : null;
            $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
            if ($currentDateAsString !== $newDateAsString) {
                $this->modified = $newDateAsString;
                $this->modifiedColumns[] = DamagesUsersPeer::MODIFIED;
            }
        } // if either are not null


        return $this;
    } // setModified()

    /**
     * Indicates whether the columns in this object are only set to default values.
     *
     * This method can be used in conjunction with isModified() to indicate whether an object is both
     * modified _and_ has some values set which are non-default.
     *
     * @return boolean Whether the columns in this object are only been set with default values.
     */
    public function hasOnlyDefaultValues()
    {
            if ($this->force_password_change !== 1) {
                return false;
            }

        // otherwise, everything was equal, so return true
        return true;
    } // hasOnlyDefaultValues()

    /**
     * Hydrates (populates) the object variables with values from the database resultset.
     *
     * An offset (0-based "start column") is specified so that objects can be hydrated
     * with a subset of the columns in the resultset rows.  This is needed, for example,
     * for results of JOIN queries where the resultset row includes columns from two or
     * more tables.
     *
     * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
     * @param int $startcol 0-based offset column which indicates which restultset column to start with.
     * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
     * @return int             next starting column
     * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
     */
    public function hydrate($row, $startcol = 0, $rehydrate = false)
    {
        try {

            $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
            $this->permission_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
            $this->email = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
            $this->first_name = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
            $this->last_name = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
            $this->position = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
            $this->phone = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
            $this->phone_mobile = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
            $this->phone_fax = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null;
            $this->password = ($row[$startcol + 9] !== null) ? (string) $row[$startcol + 9] : null;
            $this->force_password_change = ($row[$startcol + 10] !== null) ? (int) $row[$startcol + 10] : null;
            $this->created = ($row[$startcol + 11] !== null) ? (string) $row[$startcol + 11] : null;
            $this->modified = ($row[$startcol + 12] !== null) ? (string) $row[$startcol + 12] : null;
            $this->resetModified();

            $this->setNew(false);

            if ($rehydrate) {
                $this->ensureConsistency();
            }

            return $startcol + 13; // 13 = DamagesUsersPeer::NUM_HYDRATE_COLUMNS.

        } catch (Exception $e) {
            throw new PropelException("Error populating DamagesUsers object", $e);
        }
    }

    /**
     * Checks and repairs the internal consistency of the object.
     *
     * This method is executed after an already-instantiated object is re-hydrated
     * from the database.  It exists to check any foreign keys to make sure that
     * the objects related to the current object are correct based on foreign key.
     *
     * You can override this method in the stub class, but you should always invoke
     * the base method from the overridden method (i.e. parent::ensureConsistency()),
     * in case your model changes.
     *
     * @throws PropelException
     */
    public function ensureConsistency()
    {

        if ($this->aPermissions !== null && $this->permission_id !== $this->aPermissions->getId()) {
            $this->aPermissions = null;
        }
    } // ensureConsistency

    /**
     * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
     *
     * This will only work if the object has been saved and has a valid primary key set.
     *
     * @param boolean $deep (optional) Whether to also de-associated any related objects.
     * @param PropelPDO $con (optional) The PropelPDO connection to use.
     * @return void
     * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
     */
    public function reload($deep = false, PropelPDO $con = null)
    {
        if ($this->isDeleted()) {
            throw new PropelException("Cannot reload a deleted object.");
        }

        if ($this->isNew()) {
            throw new PropelException("Cannot reload an unsaved object.");
        }

        if ($con === null) {
            $con = Propel::getConnection(DamagesUsersPeer::DATABASE_NAME, Propel::CONNECTION_READ);
        }

        // We don't need to alter the object instance pool; we're just modifying this instance
        // already in the pool.

        $stmt = DamagesUsersPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
        $row = $stmt->fetch(PDO::FETCH_NUM);
        $stmt->closeCursor();
        if (!$row) {
            throw new PropelException('Cannot find matching row in the database to reload object values.');
        }
        $this->hydrate($row, 0, true); // rehydrate

        if ($deep) {  // also de-associate any related objects?

            $this->aPermissions = null;
            $this->collSessionss = null;

            $this->collCarDamagessRelatedByLsId = null;

            $this->collCarDamagessRelatedByOlId = null;

            $this->collUserDealerss = null;

        } // if (deep)
    }

    /**
     * Removes this object from datastore and sets delete attribute.
     *
     * @param PropelPDO $con
     * @return void
     * @throws PropelException
     * @throws Exception
     * @see        BaseObject::setDeleted()
     * @see        BaseObject::isDeleted()
     */
    public function delete(PropelPDO $con = null)
    {
        if ($this->isDeleted()) {
            throw new PropelException("This object has already been deleted.");
        }

        if ($con === null) {
            $con = Propel::getConnection(DamagesUsersPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
        }

        $con->beginTransaction();
        try {
            $deleteQuery = DamagesUsersQuery::create()
                ->filterByPrimaryKey($this->getPrimaryKey());
            $ret = $this->preDelete($con);
            if ($ret) {
                $deleteQuery->delete($con);
                $this->postDelete($con);
                $con->commit();
                $this->setDeleted(true);
            } else {
                $con->commit();
            }
        } catch (Exception $e) {
            $con->rollBack();
            throw $e;
        }
    }

    /**
     * Persists this object to the database.
     *
     * If the object is new, it inserts it; otherwise an update is performed.
     * All modified related objects will also be persisted in the doSave()
     * method.  This method wraps all precipitate database operations in a
     * single transaction.
     *
     * @param PropelPDO $con
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     * @throws PropelException
     * @throws Exception
     * @see        doSave()
     */
    public function save(PropelPDO $con = null)
    {
        if ($this->isDeleted()) {
            throw new PropelException("You cannot save an object that has been deleted.");
        }

        if ($con === null) {
            $con = Propel::getConnection(DamagesUsersPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
        }

        $con->beginTransaction();
        $isInsert = $this->isNew();
        try {
            $ret = $this->preSave($con);
            if ($isInsert) {
                $ret = $ret && $this->preInsert($con);
            } else {
                $ret = $ret && $this->preUpdate($con);
            }
            if ($ret) {
                $affectedRows = $this->doSave($con);
                if ($isInsert) {
                    $this->postInsert($con);
                } else {
                    $this->postUpdate($con);
                }
                $this->postSave($con);
                DamagesUsersPeer::addInstanceToPool($this);
            } else {
                $affectedRows = 0;
            }
            $con->commit();

            return $affectedRows;
        } catch (Exception $e) {
            $con->rollBack();
            throw $e;
        }
    }

    /**
     * Performs the work of inserting or updating the row in the database.
     *
     * If the object is new, it inserts it; otherwise an update is performed.
     * All related objects are also updated in this method.
     *
     * @param PropelPDO $con
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     * @throws PropelException
     * @see        save()
     */
    protected function doSave(PropelPDO $con)
    {
        $affectedRows = 0; // initialize var to track total num of affected rows
        if (!$this->alreadyInSave) {
            $this->alreadyInSave = true;

            // We call the save method on the following object(s) if they
            // were passed to this object by their coresponding set
            // method.  This object relates to these object(s) by a
            // foreign key reference.

            if ($this->aPermissions !== null) {
                if ($this->aPermissions->isModified() || $this->aPermissions->isNew()) {
                    $affectedRows += $this->aPermissions->save($con);
                }
                $this->setPermissions($this->aPermissions);
            }

            if ($this->isNew() || $this->isModified()) {
                // persist changes
                if ($this->isNew()) {
                    $this->doInsert($con);
                } else {
                    $this->doUpdate($con);
                }
                $affectedRows += 1;
                $this->resetModified();
            }

            if ($this->sessionssScheduledForDeletion !== null) {
                if (!$this->sessionssScheduledForDeletion->isEmpty()) {
                    DamagesSessionsQuery::create()
                        ->filterByPrimaryKeys($this->sessionssScheduledForDeletion->getPrimaryKeys(false))
                        ->delete($con);
                    $this->sessionssScheduledForDeletion = null;
                }
            }

            if ($this->collSessionss !== null) {
                foreach ($this->collSessionss as $referrerFK) {
                    if (!$referrerFK->isDeleted()) {
                        $affectedRows += $referrerFK->save($con);
                    }
                }
            }

            if ($this->carDamagessRelatedByLsIdScheduledForDeletion !== null) {
                if (!$this->carDamagessRelatedByLsIdScheduledForDeletion->isEmpty()) {
                    foreach ($this->carDamagessRelatedByLsIdScheduledForDeletion as $carDamagesRelatedByLsId) {
                        // need to save related object because we set the relation to null
                        $carDamagesRelatedByLsId->save($con);
                    }
                    $this->carDamagessRelatedByLsIdScheduledForDeletion = null;
                }
            }

            if ($this->collCarDamagessRelatedByLsId !== null) {
                foreach ($this->collCarDamagessRelatedByLsId as $referrerFK) {
                    if (!$referrerFK->isDeleted()) {
                        $affectedRows += $referrerFK->save($con);
                    }
                }
            }

            if ($this->carDamagessRelatedByOlIdScheduledForDeletion !== null) {
                if (!$this->carDamagessRelatedByOlIdScheduledForDeletion->isEmpty()) {
                    foreach ($this->carDamagessRelatedByOlIdScheduledForDeletion as $carDamagesRelatedByOlId) {
                        // need to save related object because we set the relation to null
                        $carDamagesRelatedByOlId->save($con);
                    }
                    $this->carDamagessRelatedByOlIdScheduledForDeletion = null;
                }
            }

            if ($this->collCarDamagessRelatedByOlId !== null) {
                foreach ($this->collCarDamagessRelatedByOlId as $referrerFK) {
                    if (!$referrerFK->isDeleted()) {
                        $affectedRows += $referrerFK->save($con);
                    }
                }
            }

            if ($this->userDealerssScheduledForDeletion !== null) {
                if (!$this->userDealerssScheduledForDeletion->isEmpty()) {
                    DamagesUserDealersQuery::create()
                        ->filterByPrimaryKeys($this->userDealerssScheduledForDeletion->getPrimaryKeys(false))
                        ->delete($con);
                    $this->userDealerssScheduledForDeletion = null;
                }
            }

            if ($this->collUserDealerss !== null) {
                foreach ($this->collUserDealerss as $referrerFK) {
                    if (!$referrerFK->isDeleted()) {
                        $affectedRows += $referrerFK->save($con);
                    }
                }
            }

            $this->alreadyInSave = false;

        }

        return $affectedRows;
    } // doSave()

    /**
     * Insert the row in the database.
     *
     * @param PropelPDO $con
     *
     * @throws PropelException
     * @see        doSave()
     */
    protected function doInsert(PropelPDO $con)
    {
        $this->modifiedColumns[] = DamagesUsersPeer::ID;
        $criteria = $this->buildCriteria();
        if ($criteria->keyContainsValue(DamagesUsersPeer::ID) ) {
            throw new PropelException('Cannot insert a value for auto-increment primary key (' . DamagesUsersPeer::ID . ')');
        }
        // remove pkey col since this table uses auto-increment and passing a null value for it is not valid
        $criteria->remove(DamagesUsersPeer::ID);
        $pk = BasePeer::doInsert($criteria, $con);
        $this->setId($pk);  //[IMV] update autoincrement primary key
        $this->setNew(false);
    }

    /**
     * Update the row in the database.
     *
     * @param PropelPDO $con
     *
     * @see        doSave()
     */
    protected function doUpdate(PropelPDO $con)
    {
        $selectCriteria = $this->buildPkeyCriteria();
        $valuesCriteria = $this->buildCriteria();
        BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
    }

    /**
     * Array of ValidationFailed objects.
     * @var        array ValidationFailed[]
     */
    protected $validationFailures = array();

    /**
     * Gets any ValidationFailed objects that resulted from last call to validate().
     *
     *
     * @return array ValidationFailed[]
     * @see        validate()
     */
    public function getValidationFailures()
    {
        return $this->validationFailures;
    }

    /**
     * Validates the objects modified field values and all objects related to this table.
     *
     * If $columns is either a column name or an array of column names
     * only those columns are validated.
     *
     * @param mixed $columns Column name or an array of column names.
     * @return boolean Whether all columns pass validation.
     * @see        doValidate()
     * @see        getValidationFailures()
     */
    public function validate($columns = null)
    {
        $res = $this->doValidate($columns);
        if ($res === true) {
            $this->validationFailures = array();

            return true;
        } else {
            $this->validationFailures = $res;

            return false;
        }
    }

    /**
     * This function performs the validation work for complex object models.
     *
     * In addition to checking the current object, all related objects will
     * also be validated.  If all pass then <code>true</code> is returned; otherwise
     * an aggreagated array of ValidationFailed objects will be returned.
     *
     * @param array $columns Array of column names to validate.
     * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
     */
    protected function doValidate($columns = null)
    {
        if (!$this->alreadyInValidation) {
            $this->alreadyInValidation = true;
            $retval = null;

            $failureMap = array();


            // We call the validate method on the following object(s) if they
            // were passed to this object by their coresponding set
            // method.  This object relates to these object(s) by a
            // foreign key reference.

            if ($this->aPermissions !== null) {
                if (!$this->aPermissions->validate($columns)) {
                    $failureMap = array_merge($failureMap, $this->aPermissions->getValidationFailures());
                }
            }


            if (($retval = DamagesUsersPeer::doValidate($this, $columns)) !== true) {
                $failureMap = array_merge($failureMap, $retval);
            }


                if ($this->collSessionss !== null) {
                    foreach ($this->collSessionss as $referrerFK) {
                        if (!$referrerFK->validate($columns)) {
                            $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                        }
                    }
                }

                if ($this->collCarDamagessRelatedByLsId !== null) {
                    foreach ($this->collCarDamagessRelatedByLsId as $referrerFK) {
                        if (!$referrerFK->validate($columns)) {
                            $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                        }
                    }
                }

                if ($this->collCarDamagessRelatedByOlId !== null) {
                    foreach ($this->collCarDamagessRelatedByOlId as $referrerFK) {
                        if (!$referrerFK->validate($columns)) {
                            $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                        }
                    }
                }

                if ($this->collUserDealerss !== null) {
                    foreach ($this->collUserDealerss as $referrerFK) {
                        if (!$referrerFK->validate($columns)) {
                            $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                        }
                    }
                }


            $this->alreadyInValidation = false;
        }

        return (!empty($failureMap) ? $failureMap : true);
    }

    /**
     * Retrieves a field from the object by name passed in as a string.
     *
     * @param string $name name
     * @param string $type The type of fieldname the $name is of:
     *               one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     *               BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     *               Defaults to BasePeer::TYPE_PHPNAME
     * @return mixed Value of field.
     */
    public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
    {
        $pos = DamagesUsersPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
        $field = $this->getByPosition($pos);

        return $field;
    }

    /**
     * Retrieves a field from the object by Position as specified in the xml schema.
     * Zero-based.
     *
     * @param int $pos position in xml schema
     * @return mixed Value of field at $pos
     */
    public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getPermissionId();
                break;
            case 2:
                return $this->getEmail();
                break;
            case 3:
                return $this->getFirstName();
                break;
            case 4:
                return $this->getLastName();
                break;
            case 5:
                return $this->getPosition();
                break;
            case 6:
                return $this->getPhone();
                break;
            case 7:
                return $this->getPhoneMobile();
                break;
            case 8:
                return $this->getPhoneFax();
                break;
            case 9:
                return $this->getPassword();
                break;
            case 10:
                return $this->getForcePasswordChange();
                break;
            case 11:
                return $this->getCreated();
                break;
            case 12:
                return $this->getModified();
                break;
            default:
                return null;
                break;
        } // switch()
    }

    /**
     * Exports the object as an array.
     *
     * You can specify the key type of the array by passing one of the class
     * type constants.
     *
     * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
     *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     *                    Defaults to BasePeer::TYPE_PHPNAME.
     * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
     * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
     * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
     *
     * @return array an associative array containing the field names (as keys) and field values
     */
    public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
    {
        if (isset($alreadyDumpedObjects['DamagesUsers'][$this->getPrimaryKey()])) {
            return '*RECURSION*';
        }
        $alreadyDumpedObjects['DamagesUsers'][$this->getPrimaryKey()] = true;
        $keys = DamagesUsersPeer::getFieldNames($keyType);
        $result = array(
            $keys[0] => $this->getId(),
            $keys[1] => $this->getPermissionId(),
            $keys[2] => $this->getEmail(),
            $keys[3] => $this->getFirstName(),
            $keys[4] => $this->getLastName(),
            $keys[5] => $this->getPosition(),
            $keys[6] => $this->getPhone(),
            $keys[7] => $this->getPhoneMobile(),
            $keys[8] => $this->getPhoneFax(),
            $keys[9] => $this->getPassword(),
            $keys[10] => $this->getForcePasswordChange(),
            $keys[11] => $this->getCreated(),
            $keys[12] => $this->getModified(),
        );
        if ($includeForeignObjects) {
            if (null !== $this->aPermissions) {
                $result['Permissions'] = $this->aPermissions->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
            }
            if (null !== $this->collSessionss) {
                $result['Sessionss'] = $this->collSessionss->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
            }
            if (null !== $this->collCarDamagessRelatedByLsId) {
                $result['CarDamagessRelatedByLsId'] = $this->collCarDamagessRelatedByLsId->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
            }
            if (null !== $this->collCarDamagessRelatedByOlId) {
                $result['CarDamagessRelatedByOlId'] = $this->collCarDamagessRelatedByOlId->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
            }
            if (null !== $this->collUserDealerss) {
                $result['UserDealerss'] = $this->collUserDealerss->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
            }
        }

        return $result;
    }

    /**
     * Sets a field from the object by name passed in as a string.
     *
     * @param string $name peer name
     * @param mixed $value field value
     * @param string $type The type of fieldname the $name is of:
     *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     *                     Defaults to BasePeer::TYPE_PHPNAME
     * @return void
     */
    public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
    {
        $pos = DamagesUsersPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);

        $this->setByPosition($pos, $value);
    }

    /**
     * Sets a field from the object by Position as specified in the xml schema.
     * Zero-based.
     *
     * @param int $pos position in xml schema
     * @param mixed $value field value
     * @return void
     */
    public function setByPosition($pos, $value)
    {
        switch ($pos) {
            case 0:
                $this->setId($value);
                break;
            case 1:
                $this->setPermissionId($value);
                break;
            case 2:
                $this->setEmail($value);
                break;
            case 3:
                $this->setFirstName($value);
                break;
            case 4:
                $this->setLastName($value);
                break;
            case 5:
                $this->setPosition($value);
                break;
            case 6:
                $this->setPhone($value);
                break;
            case 7:
                $this->setPhoneMobile($value);
                break;
            case 8:
                $this->setPhoneFax($value);
                break;
            case 9:
                $this->setPassword($value);
                break;
            case 10:
                $this->setForcePasswordChange($value);
                break;
            case 11:
                $this->setCreated($value);
                break;
            case 12:
                $this->setModified($value);
                break;
        } // switch()
    }

    /**
     * Populates the object using an array.
     *
     * This is particularly useful when populating an object from one of the
     * request arrays (e.g. $_POST).  This method goes through the column
     * names, checking to see whether a matching key exists in populated
     * array. If so the setByName() method is called for that column.
     *
     * You can specify the key type of the array by additionally passing one
     * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
     * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     * The default key type is the column's BasePeer::TYPE_PHPNAME
     *
     * @param array  $arr     An array to populate the object from.
     * @param string $keyType The type of keys the array uses.
     * @return void
     */
    public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
    {
        $keys = DamagesUsersPeer::getFieldNames($keyType);

        if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
        if (array_key_exists($keys[1], $arr)) $this->setPermissionId($arr[$keys[1]]);
        if (array_key_exists($keys[2], $arr)) $this->setEmail($arr[$keys[2]]);
        if (array_key_exists($keys[3], $arr)) $this->setFirstName($arr[$keys[3]]);
        if (array_key_exists($keys[4], $arr)) $this->setLastName($arr[$keys[4]]);
        if (array_key_exists($keys[5], $arr)) $this->setPosition($arr[$keys[5]]);
        if (array_key_exists($keys[6], $arr)) $this->setPhone($arr[$keys[6]]);
        if (array_key_exists($keys[7], $arr)) $this->setPhoneMobile($arr[$keys[7]]);
        if (array_key_exists($keys[8], $arr)) $this->setPhoneFax($arr[$keys[8]]);
        if (array_key_exists($keys[9], $arr)) $this->setPassword($arr[$keys[9]]);
        if (array_key_exists($keys[10], $arr)) $this->setForcePasswordChange($arr[$keys[10]]);
        if (array_key_exists($keys[11], $arr)) $this->setCreated($arr[$keys[11]]);
        if (array_key_exists($keys[12], $arr)) $this->setModified($arr[$keys[12]]);
    }

    /**
     * Build a Criteria object containing the values of all modified columns in this object.
     *
     * @return Criteria The Criteria object containing all modified values.
     */
    public function buildCriteria()
    {
        $criteria = new Criteria(DamagesUsersPeer::DATABASE_NAME);

        if ($this->isColumnModified(DamagesUsersPeer::ID)) $criteria->add(DamagesUsersPeer::ID, $this->id);
        if ($this->isColumnModified(DamagesUsersPeer::PERMISSION_ID)) $criteria->add(DamagesUsersPeer::PERMISSION_ID, $this->permission_id);
        if ($this->isColumnModified(DamagesUsersPeer::EMAIL)) $criteria->add(DamagesUsersPeer::EMAIL, $this->email);
        if ($this->isColumnModified(DamagesUsersPeer::FIRST_NAME)) $criteria->add(DamagesUsersPeer::FIRST_NAME, $this->first_name);
        if ($this->isColumnModified(DamagesUsersPeer::LAST_NAME)) $criteria->add(DamagesUsersPeer::LAST_NAME, $this->last_name);
        if ($this->isColumnModified(DamagesUsersPeer::POSITION)) $criteria->add(DamagesUsersPeer::POSITION, $this->position);
        if ($this->isColumnModified(DamagesUsersPeer::PHONE)) $criteria->add(DamagesUsersPeer::PHONE, $this->phone);
        if ($this->isColumnModified(DamagesUsersPeer::PHONE_MOBILE)) $criteria->add(DamagesUsersPeer::PHONE_MOBILE, $this->phone_mobile);
        if ($this->isColumnModified(DamagesUsersPeer::PHONE_FAX)) $criteria->add(DamagesUsersPeer::PHONE_FAX, $this->phone_fax);
        if ($this->isColumnModified(DamagesUsersPeer::PASSWORD)) $criteria->add(DamagesUsersPeer::PASSWORD, $this->password);
        if ($this->isColumnModified(DamagesUsersPeer::FORCE_PASSWORD_CHANGE)) $criteria->add(DamagesUsersPeer::FORCE_PASSWORD_CHANGE, $this->force_password_change);
        if ($this->isColumnModified(DamagesUsersPeer::CREATED)) $criteria->add(DamagesUsersPeer::CREATED, $this->created);
        if ($this->isColumnModified(DamagesUsersPeer::MODIFIED)) $criteria->add(DamagesUsersPeer::MODIFIED, $this->modified);

        return $criteria;
    }

    /**
     * Builds a Criteria object containing the primary key for this object.
     *
     * Unlike buildCriteria() this method includes the primary key values regardless
     * of whether or not they have been modified.
     *
     * @return Criteria The Criteria object containing value(s) for primary key(s).
     */
    public function buildPkeyCriteria()
    {
        $criteria = new Criteria(DamagesUsersPeer::DATABASE_NAME);
        $criteria->add(DamagesUsersPeer::ID, $this->id);

        return $criteria;
    }

    /**
     * Returns the primary key for this object (row).
     * @return int
     */
    public function getPrimaryKey()
    {
        return $this->getId();
    }

    /**
     * Generic method to set the primary key (id column).
     *
     * @param  int $key Primary key.
     * @return void
     */
    public function setPrimaryKey($key)
    {
        $this->setId($key);
    }

    /**
     * Returns true if the primary key for this object is null.
     * @return boolean
     */
    public function isPrimaryKeyNull()
    {

        return null === $this->getId();
    }

    /**
     * Sets contents of passed object to values from current object.
     *
     * If desired, this method can also make copies of all associated (fkey referrers)
     * objects.
     *
     * @param object $copyObj An object of DamagesUsers (or compatible) type.
     * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
     * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
     * @throws PropelException
     */
    public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
    {
        $copyObj->setPermissionId($this->getPermissionId());
        $copyObj->setEmail($this->getEmail());
        $copyObj->setFirstName($this->getFirstName());
        $copyObj->setLastName($this->getLastName());
        $copyObj->setPosition($this->getPosition());
        $copyObj->setPhone($this->getPhone());
        $copyObj->setPhoneMobile($this->getPhoneMobile());
        $copyObj->setPhoneFax($this->getPhoneFax());
        $copyObj->setPassword($this->getPassword());
        $copyObj->setForcePasswordChange($this->getForcePasswordChange());
        $copyObj->setCreated($this->getCreated());
        $copyObj->setModified($this->getModified());

        if ($deepCopy && !$this->startCopy) {
            // important: temporarily setNew(false) because this affects the behavior of
            // the getter/setter methods for fkey referrer objects.
            $copyObj->setNew(false);
            // store object hash to prevent cycle
            $this->startCopy = true;

            foreach ($this->getSessionss() as $relObj) {
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
                    $copyObj->addSessions($relObj->copy($deepCopy));
                }
            }

            foreach ($this->getCarDamagessRelatedByLsId() as $relObj) {
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
                    $copyObj->addCarDamagesRelatedByLsId($relObj->copy($deepCopy));
                }
            }

            foreach ($this->getCarDamagessRelatedByOlId() as $relObj) {
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
                    $copyObj->addCarDamagesRelatedByOlId($relObj->copy($deepCopy));
                }
            }

            foreach ($this->getUserDealerss() as $relObj) {
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
                    $copyObj->addUserDealers($relObj->copy($deepCopy));
                }
            }

            //unflag object copy
            $this->startCopy = false;
        } // if ($deepCopy)

        if ($makeNew) {
            $copyObj->setNew(true);
            $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
        }
    }

    /**
     * Makes a copy of this object that will be inserted as a new row in table when saved.
     * It creates a new object filling in the simple attributes, but skipping any primary
     * keys that are defined for the table.
     *
     * If desired, this method can also make copies of all associated (fkey referrers)
     * objects.
     *
     * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
     * @return DamagesUsers Clone of current object.
     * @throws PropelException
     */
    public function copy($deepCopy = false)
    {
        // we use get_class(), because this might be a subclass
        $clazz = get_class($this);
        $copyObj = new $clazz();
        $this->copyInto($copyObj, $deepCopy);

        return $copyObj;
    }

    /**
     * Returns a peer instance associated with this om.
     *
     * Since Peer classes are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     *
     * @return DamagesUsersPeer
     */
    public function getPeer()
    {
        if (self::$peer === null) {
            self::$peer = new DamagesUsersPeer();
        }

        return self::$peer;
    }

    /**
     * Declares an association between this object and a DamagesPermissions object.
     *
     * @param             DamagesPermissions $v
     * @return DamagesUsers The current object (for fluent API support)
     * @throws PropelException
     */
    public function setPermissions(DamagesPermissions $v = null)
    {
        if ($v === null) {
            $this->setPermissionId(NULL);
        } else {
            $this->setPermissionId($v->getId());
        }

        $this->aPermissions = $v;

        // Add binding for other direction of this n:n relationship.
        // If this object has already been added to the DamagesPermissions object, it will not be re-added.
        if ($v !== null) {
            $v->addUsers($this);
        }


        return $this;
    }


    /**
     * Get the associated DamagesPermissions object
     *
     * @param PropelPDO $con Optional Connection object.
     * @return DamagesPermissions The associated DamagesPermissions object.
     * @throws PropelException
     */
    public function getPermissions(PropelPDO $con = null)
    {
        if ($this->aPermissions === null && ($this->permission_id !== null)) {
            $this->aPermissions = DamagesPermissionsQuery::create()->findPk($this->permission_id, $con);
            /* The following can be used additionally to
                guarantee the related object contains a reference
                to this object.  This level of coupling may, however, be
                undesirable since it could result in an only partially populated collection
                in the referenced object.
                $this->aPermissions->addUserss($this);
             */
        }

        return $this->aPermissions;
    }


    /**
     * Initializes a collection based on the name of a relation.
     * Avoids crafting an 'init[$relationName]s' method name
     * that wouldn't work when StandardEnglishPluralizer is used.
     *
     * @param string $relationName The name of the relation to initialize
     * @return void
     */
    public function initRelation($relationName)
    {
        if ('Sessions' == $relationName) {
            $this->initSessionss();
        }
        if ('CarDamagesRelatedByLsId' == $relationName) {
            $this->initCarDamagessRelatedByLsId();
        }
        if ('CarDamagesRelatedByOlId' == $relationName) {
            $this->initCarDamagessRelatedByOlId();
        }
        if ('UserDealers' == $relationName) {
            $this->initUserDealerss();
        }
    }

    /**
     * Clears out the collSessionss collection
     *
     * This does not modify the database; however, it will remove any associated objects, causing
     * them to be refetched by subsequent calls to accessor method.
     *
     * @return void
     * @see        addSessionss()
     */
    public function clearSessionss()
    {
        $this->collSessionss = null; // important to set this to null since that means it is uninitialized
        $this->collSessionssPartial = null;
    }

    /**
     * reset is the collSessionss collection loaded partially
     *
     * @return void
     */
    public function resetPartialSessionss($v = true)
    {
        $this->collSessionssPartial = $v;
    }

    /**
     * Initializes the collSessionss collection.
     *
     * By default this just sets the collSessionss collection to an empty array (like clearcollSessionss());
     * however, you may wish to override this method in your stub class to provide setting appropriate
     * to your application -- for example, setting the initial array to the values stored in database.
     *
     * @param boolean $overrideExisting If set to true, the method call initializes
     *                                        the collection even if it is not empty
     *
     * @return void
     */
    public function initSessionss($overrideExisting = true)
    {
        if (null !== $this->collSessionss && !$overrideExisting) {
            return;
        }
        $this->collSessionss = new PropelObjectCollection();
        $this->collSessionss->setModel('DamagesSessions');
    }

    /**
     * Gets an array of DamagesSessions objects which contain a foreign key that references this object.
     *
     * If the $criteria is not null, it is used to always fetch the results from the database.
     * Otherwise the results are fetched from the database the first time, then cached.
     * Next time the same method is called without $criteria, the cached collection is returned.
     * If this DamagesUsers is new, it will return
     * an empty collection or the current collection; the criteria is ignored on a new object.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @return PropelObjectCollection|DamagesSessions[] List of DamagesSessions objects
     * @throws PropelException
     */
    public function getSessionss($criteria = null, PropelPDO $con = null)
    {
        $partial = $this->collSessionssPartial && !$this->isNew();
        if (null === $this->collSessionss || null !== $criteria  || $partial) {
            if ($this->isNew() && null === $this->collSessionss) {
                // return empty collection
                $this->initSessionss();
            } else {
                $collSessionss = DamagesSessionsQuery::create(null, $criteria)
                    ->filterByUsers($this)
                    ->find($con);
                if (null !== $criteria) {
                    if (false !== $this->collSessionssPartial && count($collSessionss)) {
                      $this->initSessionss(false);

                      foreach($collSessionss as $obj) {
                        if (false == $this->collSessionss->contains($obj)) {
                          $this->collSessionss->append($obj);
                        }
                      }

                      $this->collSessionssPartial = true;
                    }

                    return $collSessionss;
                }

                if($partial && $this->collSessionss) {
                    foreach($this->collSessionss as $obj) {
                        if($obj->isNew()) {
                            $collSessionss[] = $obj;
                        }
                    }
                }

                $this->collSessionss = $collSessionss;
                $this->collSessionssPartial = false;
            }
        }

        return $this->collSessionss;
    }

    /**
     * Sets a collection of Sessions objects related by a one-to-many relationship
     * to the current object.
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
     * and new objects from the given Propel collection.
     *
     * @param PropelCollection $sessionss A Propel collection.
     * @param PropelPDO $con Optional connection object
     */
    public function setSessionss(PropelCollection $sessionss, PropelPDO $con = null)
    {
        $this->sessionssScheduledForDeletion = $this->getSessionss(new Criteria(), $con)->diff($sessionss);

        foreach ($this->sessionssScheduledForDeletion as $sessionsRemoved) {
            $sessionsRemoved->setUsers(null);
        }

        $this->collSessionss = null;
        foreach ($sessionss as $sessions) {
            $this->addSessions($sessions);
        }

        $this->collSessionss = $sessionss;
        $this->collSessionssPartial = false;
    }

    /**
     * Returns the number of related DamagesSessions objects.
     *
     * @param Criteria $criteria
     * @param boolean $distinct
     * @param PropelPDO $con
     * @return int             Count of related DamagesSessions objects.
     * @throws PropelException
     */
    public function countSessionss(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    {
        $partial = $this->collSessionssPartial && !$this->isNew();
        if (null === $this->collSessionss || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collSessionss) {
                return 0;
            } else {
                if($partial && !$criteria) {
                    return count($this->getSessionss());
                }
                $query = DamagesSessionsQuery::create(null, $criteria);
                if ($distinct) {
                    $query->distinct();
                }

                return $query
                    ->filterByUsers($this)
                    ->count($con);
            }
        } else {
            return count($this->collSessionss);
        }
    }

    /**
     * Method called to associate a DamagesSessions object to this object
     * through the DamagesSessions foreign key attribute.
     *
     * @param    DamagesSessions $l DamagesSessions
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function addSessions(DamagesSessions $l)
    {
        if ($this->collSessionss === null) {
            $this->initSessionss();
            $this->collSessionssPartial = true;
        }
        if (!$this->collSessionss->contains($l)) { // only add it if the **same** object is not already associated
            $this->doAddSessions($l);
        }

        return $this;
    }

    /**
     * @param	Sessions $sessions The sessions object to add.
     */
    protected function doAddSessions($sessions)
    {
        $this->collSessionss[]= $sessions;
        $sessions->setUsers($this);
    }

    /**
     * @param	Sessions $sessions The sessions object to remove.
     */
    public function removeSessions($sessions)
    {
        if ($this->getSessionss()->contains($sessions)) {
            $this->collSessionss->remove($this->collSessionss->search($sessions));
            if (null === $this->sessionssScheduledForDeletion) {
                $this->sessionssScheduledForDeletion = clone $this->collSessionss;
                $this->sessionssScheduledForDeletion->clear();
            }
            $this->sessionssScheduledForDeletion[]= $sessions;
            $sessions->setUsers(null);
        }
    }

    /**
     * Clears out the collCarDamagessRelatedByLsId collection
     *
     * This does not modify the database; however, it will remove any associated objects, causing
     * them to be refetched by subsequent calls to accessor method.
     *
     * @return void
     * @see        addCarDamagessRelatedByLsId()
     */
    public function clearCarDamagessRelatedByLsId()
    {
        $this->collCarDamagessRelatedByLsId = null; // important to set this to null since that means it is uninitialized
        $this->collCarDamagessRelatedByLsIdPartial = null;
    }

    /**
     * reset is the collCarDamagessRelatedByLsId collection loaded partially
     *
     * @return void
     */
    public function resetPartialCarDamagessRelatedByLsId($v = true)
    {
        $this->collCarDamagessRelatedByLsIdPartial = $v;
    }

    /**
     * Initializes the collCarDamagessRelatedByLsId collection.
     *
     * By default this just sets the collCarDamagessRelatedByLsId collection to an empty array (like clearcollCarDamagessRelatedByLsId());
     * however, you may wish to override this method in your stub class to provide setting appropriate
     * to your application -- for example, setting the initial array to the values stored in database.
     *
     * @param boolean $overrideExisting If set to true, the method call initializes
     *                                        the collection even if it is not empty
     *
     * @return void
     */
    public function initCarDamagessRelatedByLsId($overrideExisting = true)
    {
        if (null !== $this->collCarDamagessRelatedByLsId && !$overrideExisting) {
            return;
        }
        $this->collCarDamagessRelatedByLsId = new PropelObjectCollection();
        $this->collCarDamagessRelatedByLsId->setModel('DamagesCarDamages');
    }

    /**
     * Gets an array of DamagesCarDamages objects which contain a foreign key that references this object.
     *
     * If the $criteria is not null, it is used to always fetch the results from the database.
     * Otherwise the results are fetched from the database the first time, then cached.
     * Next time the same method is called without $criteria, the cached collection is returned.
     * If this DamagesUsers is new, it will return
     * an empty collection or the current collection; the criteria is ignored on a new object.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     * @throws PropelException
     */
    public function getCarDamagessRelatedByLsId($criteria = null, PropelPDO $con = null)
    {
        $partial = $this->collCarDamagessRelatedByLsIdPartial && !$this->isNew();
        if (null === $this->collCarDamagessRelatedByLsId || null !== $criteria  || $partial) {
            if ($this->isNew() && null === $this->collCarDamagessRelatedByLsId) {
                // return empty collection
                $this->initCarDamagessRelatedByLsId();
            } else {
                $collCarDamagessRelatedByLsId = DamagesCarDamagesQuery::create(null, $criteria)
                    ->filterByUsersRelatedByLsId($this)
                    ->find($con);
                if (null !== $criteria) {
                    if (false !== $this->collCarDamagessRelatedByLsIdPartial && count($collCarDamagessRelatedByLsId)) {
                      $this->initCarDamagessRelatedByLsId(false);

                      foreach($collCarDamagessRelatedByLsId as $obj) {
                        if (false == $this->collCarDamagessRelatedByLsId->contains($obj)) {
                          $this->collCarDamagessRelatedByLsId->append($obj);
                        }
                      }

                      $this->collCarDamagessRelatedByLsIdPartial = true;
                    }

                    return $collCarDamagessRelatedByLsId;
                }

                if($partial && $this->collCarDamagessRelatedByLsId) {
                    foreach($this->collCarDamagessRelatedByLsId as $obj) {
                        if($obj->isNew()) {
                            $collCarDamagessRelatedByLsId[] = $obj;
                        }
                    }
                }

                $this->collCarDamagessRelatedByLsId = $collCarDamagessRelatedByLsId;
                $this->collCarDamagessRelatedByLsIdPartial = false;
            }
        }

        return $this->collCarDamagessRelatedByLsId;
    }

    /**
     * Sets a collection of CarDamagesRelatedByLsId objects related by a one-to-many relationship
     * to the current object.
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
     * and new objects from the given Propel collection.
     *
     * @param PropelCollection $carDamagessRelatedByLsId A Propel collection.
     * @param PropelPDO $con Optional connection object
     */
    public function setCarDamagessRelatedByLsId(PropelCollection $carDamagessRelatedByLsId, PropelPDO $con = null)
    {
        $this->carDamagessRelatedByLsIdScheduledForDeletion = $this->getCarDamagessRelatedByLsId(new Criteria(), $con)->diff($carDamagessRelatedByLsId);

        foreach ($this->carDamagessRelatedByLsIdScheduledForDeletion as $carDamagesRelatedByLsIdRemoved) {
            $carDamagesRelatedByLsIdRemoved->setUsersRelatedByLsId(null);
        }

        $this->collCarDamagessRelatedByLsId = null;
        foreach ($carDamagessRelatedByLsId as $carDamagesRelatedByLsId) {
            $this->addCarDamagesRelatedByLsId($carDamagesRelatedByLsId);
        }

        $this->collCarDamagessRelatedByLsId = $carDamagessRelatedByLsId;
        $this->collCarDamagessRelatedByLsIdPartial = false;
    }

    /**
     * Returns the number of related DamagesCarDamages objects.
     *
     * @param Criteria $criteria
     * @param boolean $distinct
     * @param PropelPDO $con
     * @return int             Count of related DamagesCarDamages objects.
     * @throws PropelException
     */
    public function countCarDamagessRelatedByLsId(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    {
        $partial = $this->collCarDamagessRelatedByLsIdPartial && !$this->isNew();
        if (null === $this->collCarDamagessRelatedByLsId || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collCarDamagessRelatedByLsId) {
                return 0;
            } else {
                if($partial && !$criteria) {
                    return count($this->getCarDamagessRelatedByLsId());
                }
                $query = DamagesCarDamagesQuery::create(null, $criteria);
                if ($distinct) {
                    $query->distinct();
                }

                return $query
                    ->filterByUsersRelatedByLsId($this)
                    ->count($con);
            }
        } else {
            return count($this->collCarDamagessRelatedByLsId);
        }
    }

    /**
     * Method called to associate a DamagesCarDamages object to this object
     * through the DamagesCarDamages foreign key attribute.
     *
     * @param    DamagesCarDamages $l DamagesCarDamages
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function addCarDamagesRelatedByLsId(DamagesCarDamages $l)
    {
        if ($this->collCarDamagessRelatedByLsId === null) {
            $this->initCarDamagessRelatedByLsId();
            $this->collCarDamagessRelatedByLsIdPartial = true;
        }
        if (!$this->collCarDamagessRelatedByLsId->contains($l)) { // only add it if the **same** object is not already associated
            $this->doAddCarDamagesRelatedByLsId($l);
        }

        return $this;
    }

    /**
     * @param	CarDamagesRelatedByLsId $carDamagesRelatedByLsId The carDamagesRelatedByLsId object to add.
     */
    protected function doAddCarDamagesRelatedByLsId($carDamagesRelatedByLsId)
    {
        $this->collCarDamagessRelatedByLsId[]= $carDamagesRelatedByLsId;
        $carDamagesRelatedByLsId->setUsersRelatedByLsId($this);
    }

    /**
     * @param	CarDamagesRelatedByLsId $carDamagesRelatedByLsId The carDamagesRelatedByLsId object to remove.
     */
    public function removeCarDamagesRelatedByLsId($carDamagesRelatedByLsId)
    {
        if ($this->getCarDamagessRelatedByLsId()->contains($carDamagesRelatedByLsId)) {
            $this->collCarDamagessRelatedByLsId->remove($this->collCarDamagessRelatedByLsId->search($carDamagesRelatedByLsId));
            if (null === $this->carDamagessRelatedByLsIdScheduledForDeletion) {
                $this->carDamagessRelatedByLsIdScheduledForDeletion = clone $this->collCarDamagessRelatedByLsId;
                $this->carDamagessRelatedByLsIdScheduledForDeletion->clear();
            }
            $this->carDamagessRelatedByLsIdScheduledForDeletion[]= $carDamagesRelatedByLsId;
            $carDamagesRelatedByLsId->setUsersRelatedByLsId(null);
        }
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related CarDamagessRelatedByLsId from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     */
    public function getCarDamagessRelatedByLsIdJoinCarDamagesRelatedByRelatedCarDamage($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = DamagesCarDamagesQuery::create(null, $criteria);
        $query->joinWith('CarDamagesRelatedByRelatedCarDamage', $join_behavior);

        return $this->getCarDamagessRelatedByLsId($query, $con);
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related CarDamagessRelatedByLsId from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     */
    public function getCarDamagessRelatedByLsIdJoinDictStatuses($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = DamagesCarDamagesQuery::create(null, $criteria);
        $query->joinWith('DictStatuses', $join_behavior);

        return $this->getCarDamagessRelatedByLsId($query, $con);
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related CarDamagessRelatedByLsId from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     */
    public function getCarDamagessRelatedByLsIdJoinCarData($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = DamagesCarDamagesQuery::create(null, $criteria);
        $query->joinWith('CarData', $join_behavior);

        return $this->getCarDamagessRelatedByLsId($query, $con);
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related CarDamagessRelatedByLsId from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     */
    public function getCarDamagessRelatedByLsIdJoinDictDiscards($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = DamagesCarDamagesQuery::create(null, $criteria);
        $query->joinWith('DictDiscards', $join_behavior);

        return $this->getCarDamagessRelatedByLsId($query, $con);
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related CarDamagessRelatedByLsId from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     */
    public function getCarDamagessRelatedByLsIdJoinDictPerpetrators($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = DamagesCarDamagesQuery::create(null, $criteria);
        $query->joinWith('DictPerpetrators', $join_behavior);

        return $this->getCarDamagessRelatedByLsId($query, $con);
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related CarDamagessRelatedByLsId from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     */
    public function getCarDamagessRelatedByLsIdJoinProcessTypes($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = DamagesCarDamagesQuery::create(null, $criteria);
        $query->joinWith('ProcessTypes', $join_behavior);

        return $this->getCarDamagessRelatedByLsId($query, $con);
    }

    /**
     * Clears out the collCarDamagessRelatedByOlId collection
     *
     * This does not modify the database; however, it will remove any associated objects, causing
     * them to be refetched by subsequent calls to accessor method.
     *
     * @return void
     * @see        addCarDamagessRelatedByOlId()
     */
    public function clearCarDamagessRelatedByOlId()
    {
        $this->collCarDamagessRelatedByOlId = null; // important to set this to null since that means it is uninitialized
        $this->collCarDamagessRelatedByOlIdPartial = null;
    }

    /**
     * reset is the collCarDamagessRelatedByOlId collection loaded partially
     *
     * @return void
     */
    public function resetPartialCarDamagessRelatedByOlId($v = true)
    {
        $this->collCarDamagessRelatedByOlIdPartial = $v;
    }

    /**
     * Initializes the collCarDamagessRelatedByOlId collection.
     *
     * By default this just sets the collCarDamagessRelatedByOlId collection to an empty array (like clearcollCarDamagessRelatedByOlId());
     * however, you may wish to override this method in your stub class to provide setting appropriate
     * to your application -- for example, setting the initial array to the values stored in database.
     *
     * @param boolean $overrideExisting If set to true, the method call initializes
     *                                        the collection even if it is not empty
     *
     * @return void
     */
    public function initCarDamagessRelatedByOlId($overrideExisting = true)
    {
        if (null !== $this->collCarDamagessRelatedByOlId && !$overrideExisting) {
            return;
        }
        $this->collCarDamagessRelatedByOlId = new PropelObjectCollection();
        $this->collCarDamagessRelatedByOlId->setModel('DamagesCarDamages');
    }

    /**
     * Gets an array of DamagesCarDamages objects which contain a foreign key that references this object.
     *
     * If the $criteria is not null, it is used to always fetch the results from the database.
     * Otherwise the results are fetched from the database the first time, then cached.
     * Next time the same method is called without $criteria, the cached collection is returned.
     * If this DamagesUsers is new, it will return
     * an empty collection or the current collection; the criteria is ignored on a new object.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     * @throws PropelException
     */
    public function getCarDamagessRelatedByOlId($criteria = null, PropelPDO $con = null)
    {
        $partial = $this->collCarDamagessRelatedByOlIdPartial && !$this->isNew();
        if (null === $this->collCarDamagessRelatedByOlId || null !== $criteria  || $partial) {
            if ($this->isNew() && null === $this->collCarDamagessRelatedByOlId) {
                // return empty collection
                $this->initCarDamagessRelatedByOlId();
            } else {
                $collCarDamagessRelatedByOlId = DamagesCarDamagesQuery::create(null, $criteria)
                    ->filterByUsersRelatedByOlId($this)
                    ->find($con);
                if (null !== $criteria) {
                    if (false !== $this->collCarDamagessRelatedByOlIdPartial && count($collCarDamagessRelatedByOlId)) {
                      $this->initCarDamagessRelatedByOlId(false);

                      foreach($collCarDamagessRelatedByOlId as $obj) {
                        if (false == $this->collCarDamagessRelatedByOlId->contains($obj)) {
                          $this->collCarDamagessRelatedByOlId->append($obj);
                        }
                      }

                      $this->collCarDamagessRelatedByOlIdPartial = true;
                    }

                    return $collCarDamagessRelatedByOlId;
                }

                if($partial && $this->collCarDamagessRelatedByOlId) {
                    foreach($this->collCarDamagessRelatedByOlId as $obj) {
                        if($obj->isNew()) {
                            $collCarDamagessRelatedByOlId[] = $obj;
                        }
                    }
                }

                $this->collCarDamagessRelatedByOlId = $collCarDamagessRelatedByOlId;
                $this->collCarDamagessRelatedByOlIdPartial = false;
            }
        }

        return $this->collCarDamagessRelatedByOlId;
    }

    /**
     * Sets a collection of CarDamagesRelatedByOlId objects related by a one-to-many relationship
     * to the current object.
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
     * and new objects from the given Propel collection.
     *
     * @param PropelCollection $carDamagessRelatedByOlId A Propel collection.
     * @param PropelPDO $con Optional connection object
     */
    public function setCarDamagessRelatedByOlId(PropelCollection $carDamagessRelatedByOlId, PropelPDO $con = null)
    {
        $this->carDamagessRelatedByOlIdScheduledForDeletion = $this->getCarDamagessRelatedByOlId(new Criteria(), $con)->diff($carDamagessRelatedByOlId);

        foreach ($this->carDamagessRelatedByOlIdScheduledForDeletion as $carDamagesRelatedByOlIdRemoved) {
            $carDamagesRelatedByOlIdRemoved->setUsersRelatedByOlId(null);
        }

        $this->collCarDamagessRelatedByOlId = null;
        foreach ($carDamagessRelatedByOlId as $carDamagesRelatedByOlId) {
            $this->addCarDamagesRelatedByOlId($carDamagesRelatedByOlId);
        }

        $this->collCarDamagessRelatedByOlId = $carDamagessRelatedByOlId;
        $this->collCarDamagessRelatedByOlIdPartial = false;
    }

    /**
     * Returns the number of related DamagesCarDamages objects.
     *
     * @param Criteria $criteria
     * @param boolean $distinct
     * @param PropelPDO $con
     * @return int             Count of related DamagesCarDamages objects.
     * @throws PropelException
     */
    public function countCarDamagessRelatedByOlId(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    {
        $partial = $this->collCarDamagessRelatedByOlIdPartial && !$this->isNew();
        if (null === $this->collCarDamagessRelatedByOlId || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collCarDamagessRelatedByOlId) {
                return 0;
            } else {
                if($partial && !$criteria) {
                    return count($this->getCarDamagessRelatedByOlId());
                }
                $query = DamagesCarDamagesQuery::create(null, $criteria);
                if ($distinct) {
                    $query->distinct();
                }

                return $query
                    ->filterByUsersRelatedByOlId($this)
                    ->count($con);
            }
        } else {
            return count($this->collCarDamagessRelatedByOlId);
        }
    }

    /**
     * Method called to associate a DamagesCarDamages object to this object
     * through the DamagesCarDamages foreign key attribute.
     *
     * @param    DamagesCarDamages $l DamagesCarDamages
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function addCarDamagesRelatedByOlId(DamagesCarDamages $l)
    {
        if ($this->collCarDamagessRelatedByOlId === null) {
            $this->initCarDamagessRelatedByOlId();
            $this->collCarDamagessRelatedByOlIdPartial = true;
        }
        if (!$this->collCarDamagessRelatedByOlId->contains($l)) { // only add it if the **same** object is not already associated
            $this->doAddCarDamagesRelatedByOlId($l);
        }

        return $this;
    }

    /**
     * @param	CarDamagesRelatedByOlId $carDamagesRelatedByOlId The carDamagesRelatedByOlId object to add.
     */
    protected function doAddCarDamagesRelatedByOlId($carDamagesRelatedByOlId)
    {
        $this->collCarDamagessRelatedByOlId[]= $carDamagesRelatedByOlId;
        $carDamagesRelatedByOlId->setUsersRelatedByOlId($this);
    }

    /**
     * @param	CarDamagesRelatedByOlId $carDamagesRelatedByOlId The carDamagesRelatedByOlId object to remove.
     */
    public function removeCarDamagesRelatedByOlId($carDamagesRelatedByOlId)
    {
        if ($this->getCarDamagessRelatedByOlId()->contains($carDamagesRelatedByOlId)) {
            $this->collCarDamagessRelatedByOlId->remove($this->collCarDamagessRelatedByOlId->search($carDamagesRelatedByOlId));
            if (null === $this->carDamagessRelatedByOlIdScheduledForDeletion) {
                $this->carDamagessRelatedByOlIdScheduledForDeletion = clone $this->collCarDamagessRelatedByOlId;
                $this->carDamagessRelatedByOlIdScheduledForDeletion->clear();
            }
            $this->carDamagessRelatedByOlIdScheduledForDeletion[]= $carDamagesRelatedByOlId;
            $carDamagesRelatedByOlId->setUsersRelatedByOlId(null);
        }
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related CarDamagessRelatedByOlId from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     */
    public function getCarDamagessRelatedByOlIdJoinCarDamagesRelatedByRelatedCarDamage($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = DamagesCarDamagesQuery::create(null, $criteria);
        $query->joinWith('CarDamagesRelatedByRelatedCarDamage', $join_behavior);

        return $this->getCarDamagessRelatedByOlId($query, $con);
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related CarDamagessRelatedByOlId from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     */
    public function getCarDamagessRelatedByOlIdJoinDictStatuses($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = DamagesCarDamagesQuery::create(null, $criteria);
        $query->joinWith('DictStatuses', $join_behavior);

        return $this->getCarDamagessRelatedByOlId($query, $con);
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related CarDamagessRelatedByOlId from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     */
    public function getCarDamagessRelatedByOlIdJoinCarData($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = DamagesCarDamagesQuery::create(null, $criteria);
        $query->joinWith('CarData', $join_behavior);

        return $this->getCarDamagessRelatedByOlId($query, $con);
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related CarDamagessRelatedByOlId from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     */
    public function getCarDamagessRelatedByOlIdJoinDictDiscards($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = DamagesCarDamagesQuery::create(null, $criteria);
        $query->joinWith('DictDiscards', $join_behavior);

        return $this->getCarDamagessRelatedByOlId($query, $con);
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related CarDamagessRelatedByOlId from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     */
    public function getCarDamagessRelatedByOlIdJoinDictPerpetrators($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = DamagesCarDamagesQuery::create(null, $criteria);
        $query->joinWith('DictPerpetrators', $join_behavior);

        return $this->getCarDamagessRelatedByOlId($query, $con);
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related CarDamagessRelatedByOlId from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|DamagesCarDamages[] List of DamagesCarDamages objects
     */
    public function getCarDamagessRelatedByOlIdJoinProcessTypes($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = DamagesCarDamagesQuery::create(null, $criteria);
        $query->joinWith('ProcessTypes', $join_behavior);

        return $this->getCarDamagessRelatedByOlId($query, $con);
    }

    /**
     * Clears out the collUserDealerss collection
     *
     * This does not modify the database; however, it will remove any associated objects, causing
     * them to be refetched by subsequent calls to accessor method.
     *
     * @return void
     * @see        addUserDealerss()
     */
    public function clearUserDealerss()
    {
        $this->collUserDealerss = null; // important to set this to null since that means it is uninitialized
        $this->collUserDealerssPartial = null;
    }

    /**
     * reset is the collUserDealerss collection loaded partially
     *
     * @return void
     */
    public function resetPartialUserDealerss($v = true)
    {
        $this->collUserDealerssPartial = $v;
    }

    /**
     * Initializes the collUserDealerss collection.
     *
     * By default this just sets the collUserDealerss collection to an empty array (like clearcollUserDealerss());
     * however, you may wish to override this method in your stub class to provide setting appropriate
     * to your application -- for example, setting the initial array to the values stored in database.
     *
     * @param boolean $overrideExisting If set to true, the method call initializes
     *                                        the collection even if it is not empty
     *
     * @return void
     */
    public function initUserDealerss($overrideExisting = true)
    {
        if (null !== $this->collUserDealerss && !$overrideExisting) {
            return;
        }
        $this->collUserDealerss = new PropelObjectCollection();
        $this->collUserDealerss->setModel('DamagesUserDealers');
    }

    /**
     * Gets an array of DamagesUserDealers objects which contain a foreign key that references this object.
     *
     * If the $criteria is not null, it is used to always fetch the results from the database.
     * Otherwise the results are fetched from the database the first time, then cached.
     * Next time the same method is called without $criteria, the cached collection is returned.
     * If this DamagesUsers is new, it will return
     * an empty collection or the current collection; the criteria is ignored on a new object.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @return PropelObjectCollection|DamagesUserDealers[] List of DamagesUserDealers objects
     * @throws PropelException
     */
    public function getUserDealerss($criteria = null, PropelPDO $con = null)
    {
        $partial = $this->collUserDealerssPartial && !$this->isNew();
        if (null === $this->collUserDealerss || null !== $criteria  || $partial) {
            if ($this->isNew() && null === $this->collUserDealerss) {
                // return empty collection
                $this->initUserDealerss();
            } else {
                $collUserDealerss = DamagesUserDealersQuery::create(null, $criteria)
                    ->filterByUsers($this)
                    ->find($con);
                if (null !== $criteria) {
                    if (false !== $this->collUserDealerssPartial && count($collUserDealerss)) {
                      $this->initUserDealerss(false);

                      foreach($collUserDealerss as $obj) {
                        if (false == $this->collUserDealerss->contains($obj)) {
                          $this->collUserDealerss->append($obj);
                        }
                      }

                      $this->collUserDealerssPartial = true;
                    }

                    return $collUserDealerss;
                }

                if($partial && $this->collUserDealerss) {
                    foreach($this->collUserDealerss as $obj) {
                        if($obj->isNew()) {
                            $collUserDealerss[] = $obj;
                        }
                    }
                }

                $this->collUserDealerss = $collUserDealerss;
                $this->collUserDealerssPartial = false;
            }
        }

        return $this->collUserDealerss;
    }

    /**
     * Sets a collection of UserDealers objects related by a one-to-many relationship
     * to the current object.
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
     * and new objects from the given Propel collection.
     *
     * @param PropelCollection $userDealerss A Propel collection.
     * @param PropelPDO $con Optional connection object
     */
    public function setUserDealerss(PropelCollection $userDealerss, PropelPDO $con = null)
    {
        $this->userDealerssScheduledForDeletion = $this->getUserDealerss(new Criteria(), $con)->diff($userDealerss);

        foreach ($this->userDealerssScheduledForDeletion as $userDealersRemoved) {
            $userDealersRemoved->setUsers(null);
        }

        $this->collUserDealerss = null;
        foreach ($userDealerss as $userDealers) {
            $this->addUserDealers($userDealers);
        }

        $this->collUserDealerss = $userDealerss;
        $this->collUserDealerssPartial = false;
    }

    /**
     * Returns the number of related DamagesUserDealers objects.
     *
     * @param Criteria $criteria
     * @param boolean $distinct
     * @param PropelPDO $con
     * @return int             Count of related DamagesUserDealers objects.
     * @throws PropelException
     */
    public function countUserDealerss(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    {
        $partial = $this->collUserDealerssPartial && !$this->isNew();
        if (null === $this->collUserDealerss || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collUserDealerss) {
                return 0;
            } else {
                if($partial && !$criteria) {
                    return count($this->getUserDealerss());
                }
                $query = DamagesUserDealersQuery::create(null, $criteria);
                if ($distinct) {
                    $query->distinct();
                }

                return $query
                    ->filterByUsers($this)
                    ->count($con);
            }
        } else {
            return count($this->collUserDealerss);
        }
    }

    /**
     * Method called to associate a DamagesUserDealers object to this object
     * through the DamagesUserDealers foreign key attribute.
     *
     * @param    DamagesUserDealers $l DamagesUserDealers
     * @return DamagesUsers The current object (for fluent API support)
     */
    public function addUserDealers(DamagesUserDealers $l)
    {
        if ($this->collUserDealerss === null) {
            $this->initUserDealerss();
            $this->collUserDealerssPartial = true;
        }
        if (!$this->collUserDealerss->contains($l)) { // only add it if the **same** object is not already associated
            $this->doAddUserDealers($l);
        }

        return $this;
    }

    /**
     * @param	UserDealers $userDealers The userDealers object to add.
     */
    protected function doAddUserDealers($userDealers)
    {
        $this->collUserDealerss[]= $userDealers;
        $userDealers->setUsers($this);
    }

    /**
     * @param	UserDealers $userDealers The userDealers object to remove.
     */
    public function removeUserDealers($userDealers)
    {
        if ($this->getUserDealerss()->contains($userDealers)) {
            $this->collUserDealerss->remove($this->collUserDealerss->search($userDealers));
            if (null === $this->userDealerssScheduledForDeletion) {
                $this->userDealerssScheduledForDeletion = clone $this->collUserDealerss;
                $this->userDealerssScheduledForDeletion->clear();
            }
            $this->userDealerssScheduledForDeletion[]= $userDealers;
            $userDealers->setUsers(null);
        }
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related UserDealerss from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|DamagesUserDealers[] List of DamagesUserDealers objects
     */
    public function getUserDealerssJoinDealers($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = DamagesUserDealersQuery::create(null, $criteria);
        $query->joinWith('Dealers', $join_behavior);

        return $this->getUserDealerss($query, $con);
    }

    /**
     * Clears the current object and sets all attributes to their default values
     */
    public function clear()
    {
        $this->id = null;
        $this->permission_id = null;
        $this->email = null;
        $this->first_name = null;
        $this->last_name = null;
        $this->position = null;
        $this->phone = null;
        $this->phone_mobile = null;
        $this->phone_fax = null;
        $this->password = null;
        $this->force_password_change = null;
        $this->created = null;
        $this->modified = null;
        $this->alreadyInSave = false;
        $this->alreadyInValidation = false;
        $this->clearAllReferences();
        $this->applyDefaultValues();
        $this->resetModified();
        $this->setNew(true);
        $this->setDeleted(false);
    }

    /**
     * Resets all references to other model objects or collections of model objects.
     *
     * This method is a user-space workaround for PHP's inability to garbage collect
     * objects with circular references (even in PHP 5.3). This is currently necessary
     * when using Propel in certain daemon or large-volumne/high-memory operations.
     *
     * @param boolean $deep Whether to also clear the references on all referrer objects.
     */
    public function clearAllReferences($deep = false)
    {
        if ($deep) {
            if ($this->collSessionss) {
                foreach ($this->collSessionss as $o) {
                    $o->clearAllReferences($deep);
                }
            }
            if ($this->collCarDamagessRelatedByLsId) {
                foreach ($this->collCarDamagessRelatedByLsId as $o) {
                    $o->clearAllReferences($deep);
                }
            }
            if ($this->collCarDamagessRelatedByOlId) {
                foreach ($this->collCarDamagessRelatedByOlId as $o) {
                    $o->clearAllReferences($deep);
                }
            }
            if ($this->collUserDealerss) {
                foreach ($this->collUserDealerss as $o) {
                    $o->clearAllReferences($deep);
                }
            }
        } // if ($deep)

        if ($this->collSessionss instanceof PropelCollection) {
            $this->collSessionss->clearIterator();
        }
        $this->collSessionss = null;
        if ($this->collCarDamagessRelatedByLsId instanceof PropelCollection) {
            $this->collCarDamagessRelatedByLsId->clearIterator();
        }
        $this->collCarDamagessRelatedByLsId = null;
        if ($this->collCarDamagessRelatedByOlId instanceof PropelCollection) {
            $this->collCarDamagessRelatedByOlId->clearIterator();
        }
        $this->collCarDamagessRelatedByOlId = null;
        if ($this->collUserDealerss instanceof PropelCollection) {
            $this->collUserDealerss->clearIterator();
        }
        $this->collUserDealerss = null;
        $this->aPermissions = null;
    }

    /**
     * return the string representation of this object
     *
     * @return string
     */
    public function __toString()
    {
        return (string) $this->exportTo(DamagesUsersPeer::DEFAULT_STRING_FORMAT);
    }

    /**
     * return true is the object is in saving state
     *
     * @return boolean
     */
    public function isAlreadyInSave()
    {
        return $this->alreadyInSave;
    }

}
